package com.zhuss.controller.core;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.zhuss.bean.bo.core.login.app.BindBo;
import com.zhuss.bean.bo.core.login.app.SendCodeBo;
import com.zhuss.bean.bo.core.login.app.UnbindBo;
import com.zhuss.bean.bo.core.login.app.UpdateUserBo;
import com.zhuss.bean.vo.core.login.app.SendCodeVo;
import com.zhuss.common.AbstractBo;
import com.zhuss.common.BaseController;
import com.zhuss.common.LoginOperateService;
import com.zhuss.common.Processor;
import com.zhuss.core.login.LoginServiceApp;
import com.zhuss.exception.DzcxException;


/**
 * app
 * 登录操作 controller
 * @Author zhushanshuo
   @Date 2020-04-13 19:58
 *
 */
  
 
@RestController
@RequestMapping("/login")
@Api(tags="APP端登录",value="APP端登录类")
public class LoginController extends BaseController {
	
	@Autowired
	@Qualifier("loginService")
	private LoginOperateService<Object, Object> loginService;
	
	@Autowired
	@Qualifier("loginServiceApp")
	private LoginServiceApp loginServiceApp;
	
	@Autowired
	@Qualifier("codeSend")
	private Processor<SendCodeVo, SendCodeBo> codeSend;
	
	/**
	 * 绑定
	 * 登录
	 * @param bo
	 * @throws DzcxException
	 */
	@ResponseBody
	@PostMapping("/bind")
	public Object bind(@RequestBody BindBo bo) throws DzcxException {
		
		Object result = loginServiceApp.bind(bo);
		return result;
	}
	
	
	/**
	 * 解绑
	 * 登出
	 * @param bo
	 * @throws DzcxException
	 */
	@ResponseBody
    @PostMapping("/unbind")
    public void unbind(@RequestBody UnbindBo bo) throws DzcxException {
		
		loginServiceApp.unbind(bo);
    }
	
	/**
	 * 验证码
	 * @param bo
	 * @throws WpsException
	 */
	@ResponseBody
	@PostMapping("/sendCode")
	@ApiOperation(value="【APP端】登录", notes="验证码登录")
	public Object sendCode(@RequestBody SendCodeBo bo) throws DzcxException {
		
		SendCodeBo param = (SendCodeBo) bo;
		SendCodeVo result = codeSend.process(param);
		return result;
	}
	
	
	/**
	 * app
	 * 设置个人信息
	 * 
	 * @param bo
	 * @throws DzcxException
	 */
	@ResponseBody
    @PostMapping("/updateUser")
    public Object updateUser(@RequestBody UpdateUserBo bo) throws DzcxException {
		
		Object result = loginServiceApp.updateUser(bo);
		
		return result;
    }
	
	/**
	 * app
	 * 查询个人信息
	 * 
	 * @param bo
	 * @throws DzcxException
	 */
	@ResponseBody
	@PostMapping("/info")
	public Object info(@RequestBody AbstractBo bo) throws DzcxException {
		
		Object result = loginServiceApp.info(bo);
		
		return result;
	}
	
}
